#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <algorithm>
using namespace std;

const int N = 1e8 + 10;
long long arr[N];
int n, k;

int main() {

    cin >> n >> k;
    for (int i = 0; i < n; i++)
        cin >> arr[i];

    sort(arr, arr + n);

    int left = 0;
    int right = left + 1;
    int ret = 1;
    while (right < n)
    {
        while (arr[right] - arr[left] > k)
        {
            left++;
        }
        ret = max(ret, right - left + 1);
        right++;
    }

    cout << ret << endl;

    return 0;
}